package com.group12.liuxinpeng.user.control;

import com.alibaba.fastjson.JSON;
import com.group12.liuxinpeng.common.control.BaseController;
import com.group12.liuxinpeng.mybatis.entity.PtUserEntity;
import com.group12.liuxinpeng.mybatis.flexigrid.PadingRstType;
import com.group12.liuxinpeng.mybatis.flexigrid.PagingBean;
import com.group12.liuxinpeng.mybatis.ztree.ZtreeEntity;
import com.group12.liuxinpeng.user.entity.UserSearchEntity;
import com.group12.liuxinpeng.user.service.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
    private Logger logger = LogManager.getLogger(this.getClass().getName());

    @Resource
    private UserService userService;

    @Resource
    private MessageSource messageSource;
    @RequestMapping("/userPage")
    public String userPage() {
        return "user/userPage";
    }

    @RequestMapping("/getUserInfoListByPage")
    @ResponseBody
    public PadingRstType<PtUserEntity> getUserInfoListByPage(UserSearchEntity search, PagingBean paging) {
        logger.info(search);
        PadingRstType<PtUserEntity> ptUserEntityPadingRstType = userService.getUserInfoListByPage(search, paging);
        return ptUserEntityPadingRstType;
    }

    @RequestMapping("/deleteUserById")
    @ResponseBody
    public String deleteUserById(@RequestParam("userUuid") String userUuid) {
        logger.info("userUuid" + userUuid);
        userService.deleteUserById(userUuid);
        return getSuccessMessage("user.delete.success");
    }

    @RequestMapping("/getRoleZtreeListByUserId")
    @ResponseBody
    public List<ZtreeEntity> getRoleZtreeListByUserId(@RequestParam("userUuid") String userUuid) {
        logger.info("userUuid" + userUuid);
        List<ZtreeEntity> list=userService.getRoleZtreeListByUserId1(userUuid);
        return list;
    }

    @RequestMapping("/allocateRoleByUser")
    @ResponseBody
    public String allocateRoleByUser(@RequestParam("userUuid") String userUuid,
                                     @RequestParam("roleArray") String roleArray){
        System.out.println("我进来 了");
        userService.allocateRoleByUser(userUuid,roleArray);
        return getSuccessMessage("user.allocat.role.success");
    }
}
